package com.zhiche.lisa.lspm.service.driver.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.utils.Account.AccountUtil;
import com.zhiche.lisa.core.utils.Account.JwtAccountVO;
import com.zhiche.lisa.lspm.dao.mapper.driver.DriverAuditLogMapper;
import com.zhiche.lisa.lspm.dao.model.driver.DriverAuditLog;
import com.zhiche.lisa.lspm.service.driver.IDriverAuditLogService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 司机认证日志 服务实现类
 * </p>
 *
 * @author qichao
 * @since 2018-06-10
 */
@Service
public class DriverAuditLogServiceImpl extends ServiceImpl<DriverAuditLogMapper, DriverAuditLog> implements IDriverAuditLogService {
    @Override
    public void batchInsertLog(List<Long> driverIds, Integer auditResult) throws BaseException {
        try{
            JwtAccountVO jwtAccountVO = AccountUtil.getAccountInfoFromSecurityContext();
            List<DriverAuditLog> lists = Lists.newArrayList();
            driverIds.forEach(driverId -> {
                DriverAuditLog driverAuditLog = new DriverAuditLog();
                if(Objects.nonNull(jwtAccountVO)){
                    driverAuditLog.setCreator(jwtAccountVO.getAccountId());
                    driverAuditLog.setTenantId(Long.parseLong(jwtAccountVO.getTenantId()));
                }
                driverAuditLog.setDriverId(driverId);
                driverAuditLog.setAuditResult(auditResult);
                lists.add(driverAuditLog);
            });
            this.insertBatch(lists);
        }
        catch (Exception ex){
            throw new BaseException(ex.getMessage());
        }
    }
}
